use specs::Entity;
use crate::validators::validator::Validator;

pub struct OrValidator<V1, V2> {
    v1: V1,
    v2: V2,
}

impl<V1, V2> OrValidator<V1, V2> {
    pub fn new(v1: V1, v2: V2) -> Self {
        OrValidator {
            v1,
            v2,
        }
    }
}

impl<'a, V1: Validator<'a>, V2: Validator<'a>> Validator<'a> for OrValidator<V1, V2> {
    type SystemData = (
        V1::SystemData,
        V2::SystemData,
    );

    fn validate(&mut self, (v1_data, v2_data): &Self::SystemData, performer: Entity, target: Entity) -> bool {
        self.v1.validate(v1_data, performer, target) || self.v2.validate(v2_data, performer, target)
    }
}